<?php
if (ini_get('session.auto_start') == 0)session_start();
require_once '../sub/init.php';
//if(!is_mobile() && $submitok!='ajax_get_verify')header("Location: ".HOST."/p/login.php");
require_once ZEAI.'sub/conn.php';
require_once ZEAI.'sub/www_zeai_cn_sms.php';
require_once ZEAI.'cache/config_reg.php';
require_once 'login_reg_fn.php';
$loginip=getip();
if($submitok=='admlogin'){
	if (!ifint($uid) || !ifint($uu) || str_len($pp) != 32)callmsg("Forbidden1!","-1");
	$rt = $db->query("SELECT id FROM ".__TBL_ADMIN__." WHERE id=".$uu." AND password='$pp'");
	if (!$db->num_rows($rt))exit;
	$password = trim($pwd);
	if (str_len($password) != 32){
		$password = 'www.zeai.cn_eb72c92a54_d5a330112';
		$db->query("UPDATE ".__TBL_USER__." SET pwd='$password' WHERE id=".$uid);
	}
	$rt = $db->query("SELECT id,pwd,flag,sex,nickname,grade,birthday,ifadm,RZ,photo_s,photo_f,myinfobfb FROM ".__TBL_USER__." WHERE id=".$uid." AND pwd='$password'  AND (flag=1 || flag=-2)");
	if(!$db->num_rows($rt)){
		callmsg("● 用户名/密码错误/或不存在！","-1");
	} else {
		$row = $db->fetch_array($rt,'name');
		setUcookie($row);
		$jumpurl = (empty($jumpurl))?'':$jumpurl;
		$uid=$row[0];
		AddLog2('进入用户【'.dataIO($row[4],'out').'（uid:'.$uid.'）】个人中心');
		header("Location: ".mHref('my'));exit;
	}
}
//if (!is_mobile())exit('请用手机浏览器打开');
switch ($submitok) {
	case 'login_forgetpass_update':
		$mob = $mob2;$verify=$verify2;
		if (!ifmob($mob))json_exit(array('flag'=>0,'msg'=>'请输入正确的手机号码'));
		if (str_len($newpass) > 20 || str_len($newpass) < 6)json_exit(array('flag'=>0,'msg'=>'新密码长度请控制在6~20长度'));
		$row = $db->ROW(__TBL_USER__,'id',"mob='".$mob."' AND FIND_IN_SET('mob',RZ) ");
		if(!$row)json_exit(array('flag'=>0,'msg'=>'此手机号码未注册或未认证,请重新输入'));
		//验证码处理
		$verify = intval($verify);
		if (empty($_SESSION['Zeai_cn__verify'])){
			json_exit(array('flag'=>0,'msg'=>'短信验证码错误，请重新获取'));
		}else{
			if ($_SESSION['Zeai_cn__verify'] != $verify){
				json_exit(array('flag'=>0,'msg'=>'短信验证码不正确'));
			}
			if ($_SESSION['Zeai_cn__mob'] != $mob && ifmob($mob)){
				unset($_SESSION["Zeai_cn__verify"]);
				unset($_SESSION["Zeai_cn__mob"]);
				json_exit(array('flag'=>0,'msg'=>'手机号码异常，请重新获取'));
			}
		}
		$db->query("UPDATE ".__TBL_USER__." SET pwd='".md5($newpass)."' WHERE mob='$mob'");
		json_exit(array('flag'=>1,'msg'=>$msg,'newpass'=>$newpass));	
	break;
	case 'ajax_click_yzm':
		$yzmarr = array('壹'=>'1','贰'=>'2','叁'=>'3','肆'=>'4','伍'=>'5','陆'=>'6','柒'=>'7','捌'=>'8','玖'=>'9','零'=>'0');
		$_SESSION['colorKey'] = array_rand($yzmarr,1);
		$_SESSION['colorV']   = $yzmarr[$_SESSION['colorKey']];
		$yzmarr_new=shuffle_arr($yzmarr);
		foreach ($yzmarr_new as $k=>$V) {$echo.= '<li class=breath>'.$V.'</li>';}
		json_exit(array('flag'=>1,'key'=>$_SESSION['colorKey'],'li'=>$echo));	
	break;
	case 'ajax_click_yzm_chk':
		if($v==$_SESSION['colorV'] && $key==$_SESSION['colorKey']){
			json_exit(array('flag'=>1,'msg'=>'好样的，选择正确，正在发送手机验证码'));
		}else{
			json_exit(array('flag'=>0,'msg'=>'选择错误，请重新选择'));
		}
	break;
	case 'ajax_reg_verify':
		if ($TG_set['regkind'] == 2)exit(JSON_ERROR);
		if(  $v!=$_SESSION['colorV'] || $key!=$_SESSION['colorKey'] ){json_exit(array('flag'=>0,'msg'=>'选择错误，请重新选择获取！'));}
		unset($_SESSION["colorKey"]);
		unset($_SESSION["colorV"]);
		if(!ifmob($mob))json_exit(array('flag'=>0,'msg'=>'请输入正确的手机号码'));
		if (($Temp_regyzmrenum > $_SMS['sms_yzmnum']) && $_SMS['sms_yzmnum']>0  )json_exit(array('flag'=>0,'msg'=>'你重复发送次数过多，已暂停发送'));
		$_SESSION['Zeai_cn__verify'] = cdstr(4);
		//sms
		$rtn = Zeai_sendsms_authcode($mob,$_SESSION['Zeai_cn__verify']);
		//$rtn=0;
		if ($rtn == 0){
			setcookie("Temp_regyzmrenum",$Temp_regyzmrenum+1,time()+31536000,"/",$_ZEAI['CookDomain']);  
			$chkflag = 1;
			$content = '验证码发送成功，请注意查收';//.$_SESSION['Zeai_cn__verify']
		}else{
			$chkflag = 0;
			$content = "发送失败,错误码：$rtn"."-".sms_error($rtn);
		}
		//sms end
		$_SESSION['Zeai_cn__mob'] = $mob;
		json_exit(array('flag'=>$chkflag,'msg'=>$content));
	break;
}
/**是否库里有**/
if (is_weixin()){
	if(str_len($cook_openid)>20){
		$server_openid = $cook_openid;
	}else{
		$server_openid = wx_get_openid(0);
		setcookie("cook_openid",$server_openid,time()+31536000,"/",$_ZEAI['CookDomain']);
	}
	if(str_len($server_openid)>20){
		chk_flag1Fn(" openid='".$server_openid."'");
	}
}elseif(ifint($cook_uid) && !empty($cook_pwd)){
	$dataflag = chk_flag1Fn("id=".$cook_uid." AND pwd='".trimhtml($cook_pwd)."' ");
	if($dataflag==2){
		$nexturl = ($_REG['reg_style'] == 2)?'reg_diy':'reg_alone';
		header("Location: ".$nexturl.'.php');exit;
	}
}elseif(ifint($cook_tg_uid) && !empty($cook_tg_pwd)){//推广是否有绑定
	$rowtg = $db->ROW(__TBL_TG_USER__,"uid","id=".$cook_tg_uid." AND pwd='$cook_tg_pwd'","name");
	if ($rowtg){
		$rowu = $db->ROW(__TBL_USER__,"id,pwd","id=".intval($rowtg['uid']),"name");
		if ($rowu){
			$dataflag = chk_flag1Fn("id=".$rowu['id']." AND pwd='".$rowu['pwd']."' ");
			if($dataflag==2){
				$nexturl = ($_REG['reg_style'] == 2)?'reg_diy':'reg_alone';
				header("Location: ".$nexturl.'.php');exit;
			}
		}
	}
}
//微信自动进入
if(is_weixin() && empty($submitok)){
/*	if(isset($cook_openid) && !empty($cook_openid) ){
		$server_openid = $cook_openid;
	}else{
		$server_openid = wx_get_openid(0);
		setcookie("cook_openid",$server_openid,time()+31536000,"/",$_ZEAI['CookDomain']);
	}
*/
	$row = $db->ROW(__TBL_USER__,"id,uname,nickname,pwd,sex,photo_s,grade,birthday,flag,ifadm,RZ,photo_s,photo_f,myinfobfb","openid<>'' AND openid='".$server_openid."'","name");
	if ($row){
		if ($row['flag']==-1){
			alert('您的帐号已被注销或锁定','back');
		}elseif($row['flag']==0){
			alert('您已注册成功，请等待我们进行帐号审核','back');
		}elseif($row['flag']==2){
			setUcookie($row);
			$regurl=($_REG['reg_style']==1)?'reg_alone':'reg_diy';
			header("Location: ".HOST."/m/".$regurl.".php");
		}else{
			$db->query("UPDATE ".__TBL_USER__." SET endtime=".ADDTIME.",endip='$loginip',logincount=logincount+1 WHERE id=".$row['id']);
			setUcookie($row);
			$jumpurl = urldecode($jumpurl);
			$jumpurl = (empty($jumpurl) || strpos($jumpurl,'login.php') !== false  )?mHref('my'):$jumpurl;
			header("Location: ".$jumpurl);
		}
	}
}
$headertitle = '单身用户登录-';$nav = 'my';
?>
<!doctype html><html><head><meta charset="utf-8">
<title><?php echo $headertitle;?><?php echo $_ZEAI['siteName'];?></title>
<?php echo HEADMETA; ?>
<meta name="generator" content="Zeai.cn V9" />
<link href="<?php echo RES;?>m/css/m.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<script src="<?php echo RES;?>www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/m.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/login.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<link href="<?php echo HOST;?>/cache/zeaicolor.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo RES;?>m/css/login.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<style>
.TRnav_btn i{color:#aaa}
.login .box button,.forgetpassbox button{box-shadow:0 .3rem .8rem rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.4);background-color:#fff;background:-webkit-linear-gradient(315deg,rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.6) 0%,<?php echo $_ZEAI['mob_mbcolor'];?> 100%)}
</style>
<script>var reg_kind=<?php echo intval($_REG['reg_kind']);?></script>
</head><body><?php
$mini_class='top_mini4';
require_once ZEAI.'m/top_mini.php';?>
<main class="login">
    <h1>登录注册更精彩</h1>
    <h5>登录注册表示同意 <a id="clause" class="zeaicolor">《用户协议、隐私条款》</a></h5>
    <div class="box">
        <form id="WWW__ZEAI_CN_form">
			<?php if($_REG['reg_kind'] == 1){?>
                <div id="mobbox">
                    <dl><dt><i class="ico">&#xe627;</i></dt><dd><input required name="mob" type="text" id="mob" placeholder="请输入手机号" autocomplete="off" maxlength="11" pattern="[0-9]*" onBlur="zeai.setScrollTop(0);"></dd></dl>
                    <dl><dt><i class="ico" style="font-size:2rem">&#xe6c3;</i></dt><dd class="yzmF">
                    <input name="verify" id="verify" type="text" required maxlength="4" placeholder="请输入验证码" autocomplete="off"  onBlur="zeai.setScrollTop(0);"  pattern="[0-9]*" /><a href="javascript:verifyFn(yzmbtn);" class="yzmbtn" id="yzmbtn">获取验证码</a>
                    </dd></dl>
                </div>
                <div id="zeai_yzm" class="divTopDown"><em id="zeai_yzm_em"></em><span>对应的小写是？点击下面数字确定</span><div class="text" id="zeai_yzm_li"></div></div>
			<?php }elseif($_REG['reg_kind'] == 2){?>
                <div id="unamebox">
                    <dl><dt><i class="ico">&#xe664;</i></dt><dd><input name="uname" type="text" class="input_login" id="uname" placeholder="ID / 手机 / 用户名" autocomplete="off" maxlength="15"></dd></dl>
                    <dl><dt><i class="ico">&#xe620;</i></dt><dd><input name="pwd" type="password" class="input_login" id="pwd" placeholder="密码" autocomplete="off" maxlength="20"><span class="ico" onClick="showpass(this);">&#xe61c;</span></dd></dl>
                    <div class="regfindpass">
						<?php
                        $regurl = ($_REG['reg_style'] == 2)?'reg_diy.php':'reg_alone.php';
                        $regurl .= '?tguid='.intval($tguid).'&admid='.intval($admid).'&tmpid='.intval($tmpid).'&subscribe='.intval($subscribe);?>
                        <a href="<?php echo $regurl;?>">注册新帐号</a>
                        <a id="forgetpass_btn">忘记密码</a><div class="clear"></div>
                    </div>
                </div>
            <?php }?>
            <button type="button" class="btn size4 zeaibg yuan" onClick="regbtnFn();">登录/注册</button>
            <input type="hidden" id="jumpurl" name="jumpurl" value="<?php echo $jumpurl;?>">
            <input type="hidden" name="tguid" id="tguid" value="<?php echo intval($tguid);?>">
            <input type="hidden" name="tmpid" id="tmpid" value="<?php echo intval($tmpid);?>">
            <input type="hidden" name="admid" id="admid" value="<?php echo intval($admid);?>">
            <input type="hidden" name="subscribe" id="subscribe" value="<?php echo intval($subscribe);?>">
            <input type="hidden" name="fromurl" value="login">
            <input type="hidden" name="submitok" value="ajax_uname_addupdate">
        </form>
        <div class="clear"></div>
    </div>
</main>
<?php if($_REG['reg_kind'] == 2){?>
<div id="forgetpassbox" class="forgetpass" style="display:none">
    <div class="forgetpassbox">
        <form id="WWW__ZEAI_CN_form2">
            <dl style="padding-top:0px;margin-top:0"><dt><i class="ico">&#xe627;</i></dt><dd><input name="mob2" type="text" class="input_login" id="mob2" placeholder="请输入手机号码" autocomplete="off" maxlength="11" pattern="[0-9]*" onBlur="zeai.setScrollTop(0);"></dd></dl>
            <dl><dt><i class="ico">&#xe6c3;</i></dt><dd class="yzmF">
            <input name="verify2" id="verify2" type="text" required class="input_login" maxlength="4" placeholder="输入短信验证码" autocomplete="off"  onBlur="zeai.setScrollTop(0);" /><a href="javascript:;" class="yzmbtn" id="yzmbtn2">获取验证码</a>
            </dd></dl>
            <dl style="padding-top:0px;margin-top:0"><dt><i class="ico">&#xe620;</i></dt><dd><input name="newpass" type="text" class="input_login" id="newpass" placeholder="请输入新密码6~20长度" maxlength="20"></dd></dl>
            <button type="button" class="btn size4 zeaibg yuan" onClick="forgetpassFn();">修改密码</button>
        </form>
        <div class="ok" id="ok">
            <i class="ico flag">&#xe60f;</i>
            <h4 class="textok">密码重置成功，请牢记</h4>
            <h4 class="title"><span>您的新密码为：</span><b id="newpassstr"></b>　<a class="btn size1 BAI" onclick="zeai.copy(newpassstr.innerHTML,function(){zeai.msg('复制成功');})">复制密码</a></h4>
        </div>
    </div>
</div>
<?php }?>
<?php require_once ZEAI.'m/TRnav.php';?>
<div id="clausebox">
	<i class='ico Ugoback' onclick="div_left_mask.click()">&#xeaca;</i>
    <div class="title">用户协议、隐私条款</div>
	<div class="C"><?php $row = $db->ROW(__TBL_NEWS__,"content","id=1");$content = '';if($row)echo dataIO($row[0],'outadm');?></div>
</div>
</body></html>
<?php 
function AddLog2($c) {
	global $db,$_SESSION,$uid,$tguid,$tg_uid;
	$session_uname   = $_SESSION["admuname"];
	$session_kind    = $_SESSION["kind"];//adm,crm
	$session_agentid = intval($_SESSION["agentid"]);
	$session_agenttitle  = $_SESSION["agenttitle"];
	$kind=($session_kind=='crm')?2:1;$c=dataIO($c,'in',2000);$uid=intval($uid);$tguid=(ifint($tg_uid))?$tg_uid:intval($tguid);
	$db->query("INSERT INTO ".__TBL_LOG__." (username,kind,content,addtime,agentid,agenttitle,uid,tguid) VALUES ('$session_uname',$kind,'$c',".ADDTIME.",$session_agentid,'$session_agenttitle',$uid,$tguid)");
}?>